home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Frameworks / TransSkel 3.24 / Demos / C Demos / Button / Modal1.c < prev    next >
Text File  |  1995-03-21  |  2KB  |  88 lines

  1. /*
  2.  * Modal Dialog 1
  3.  *
  4.  * This dialog consists of an OK button that's always the default button,
  5.  * a Cancel button, an edittext item, and a user item that's used for
  6.  * drawing the outline around the default button.
  7.  *
  8.  * The dialog arranges that the OK button is active only when there is text
  9.  * in the edittext item.  The Cancel button is always active so the user
  10.  * can get out of the dialog even when there's no text in the edittext item.
  11.  *
  12.  * This dialog demonstrates:
  13.  * - How to install an outliner for the default item, where the default is
  14.  * the button that's specified in the dialog template as the default.
  15.  * - How to make sure the outline is redrawn properly when the hiliting
  16.  * state of the outlined button changes.
  17.  */
  18.  
  19. # include    "TransSkel.h"
  20.  
  21. # include    "Button.h"
  22.  
  23.  
  24. typedef enum
  25. {
  26.     iOK = 1,
  27.     iCancel,
  28.     iEditText,
  29.     iOutline
  30. };
  31.  
  32.  
  33.  
  34. void
  35. DoModal1 (void)
  36. {
  37. ModalFilterUPP    filter;
  38. DialogPtr    dlog;
  39. GrafPtr    savePort;
  40. short    item;
  41. Str255    str;
  42.  
  43.     dlog = GetNewDialog (modal1Res, nil, (WindowPtr) -1L);
  44.     if (dlog == (DialogPtr) nil)
  45.     {
  46.         SysBeep (1);
  47.         return;
  48.     }
  49.  
  50.     SkelPositionWindow (dlog, skelPositionOnMainDevice, horizRatio, vertRatio);
  51.  
  52.     GetPort (&savePort);
  53.     SetPort (dlog);
  54.  
  55.     SkelSetDlogButtonOutliner (dlog, iOutline);
  56.     SkelSetDlogStr (dlog, iEditText,
  57.         "\pDefault button is active only when this field is non-empty");
  58.     SelectDialogItemText (dlog, iEditText, 0, 32767);
  59.  
  60.     ShowWindow (dlog);
  61.  
  62.     for (;;)
  63.     {
  64.         /*
  65.          * Tell the standard filter to map return/enter to the default
  66.          * item (iOK).  Also map escape/command-period to Cancel.
  67.          */
  68.         filter = SkelDlogFilter (nil, true);
  69.         SkelDlogCancelItem (iCancel);
  70.         SkelDlogTracksCursor (true);
  71.         ModalDialog (filter, &item);
  72.         SkelRmveDlogFilter ();
  73.         if (item == iOK || item == iCancel)
  74.             break;
  75.  
  76.         /*
  77.          * Set hiliting of default button according to whether or not
  78.          * the edittext item now has anything in it.  If hiliting changes,
  79.          * redraw outline.
  80.          */
  81.         SkelGetDlogStr (dlog, iEditText, str);
  82.         if (SkelSetDlogCtlHilite (dlog, iOK, str[0] > 0 ? normalHilite : dimHilite))
  83.             SkelDrawButtonOutline (SkelGetDlogCtl (dlog, iOK));
  84.     }
  85.     DisposeDialog (dlog);
  86.     SetPort (savePort);
  87. }
  88.